package acwing._2LanQiao._6DoublePointer_BFS_Graph;
/**
 * @Project : ProgrammingExercises
 * @Package : ACWing._2LanQiao._6DoublePointer_BFS_Graph
 * @File : Q1113.java
 * @Author : WangRuoyu
 * @Date : 2023/3/19 14:07
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;

public class Q1113 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line = br.readLine();

        while (!line.equals("0 0")) {
            String[] words = line.split(" ");
            int n = Integer.parseInt(words[0]);
            int m = Integer.parseInt(words[1]);

            boolean[][] visited = new boolean[m][n];

            int start = 0;
            for (int i = 0; i < m; ++i) {
                line = br.readLine();
                for (int j = 0; j < n; ++j) {
                    if (line.charAt(j) == '#') {
                        visited[i][j] = true;
                    } else if (line.charAt(j) == '@') {
                        start = i * n + j;
                        visited[i][j] = true;
                    }
                }
            }

            Queue<Integer> q = new LinkedList<>();

            q.add(start);

            int res = 0;
            while (!q.isEmpty()) {
                int node = q.poll();
                res++;
                int x = node / n;
                int y = node % n;
                if (x > 0 && !visited[x - 1][y]) {
                    q.add((x - 1) * n + y);
                    visited[x - 1][y] = true;
                }
                if (x < m - 1 && !visited[x + 1][y]) {
                    q.add((x + 1) * n + y);
                    visited[x + 1][y] = true;
                }
                if (y > 0 && !visited[x][y - 1]) {
                    q.add(x * n + y - 1);
                    visited[x][y - 1] = true;
                }
                if (y < n - 1 && !visited[x][y + 1]) {
                    q.add(x * n + y + 1);
                    visited[x][y + 1] = true;
                }
            }

            System.out.println(res);

            line = br.readLine();
        }
    }
}
